package com.wen.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wen.yygh.common.result.Result;
import com.wen.yygh.model.user.UserInfo;
import com.wen.yygh.user.service.UserService;
import com.wen.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Wenjl
 */
@RestController
@RequestMapping("/admin/user")
@Slf4j
@Api(tags = "用户信息管理")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户信息列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable("page") Long page,
                       @PathVariable("limit") Long limit,
                       UserInfoQueryVo userInfoQueryVo) {
        //创建分页对象
        Page<UserInfo> pageParam = new Page<>(page, limit);
        //最终查询结果
        IPage result = userService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(result);
    }

    @ApiOperation("锁定用户")
    @PutMapping("/lock/{id}/{status}")
    public Result lock(@PathVariable("id") Long id,
                       @PathVariable("status") Integer status) {

        userService.lock(id, status);
        return Result.ok();
    }

    @ApiOperation("查看用户详情")
    @GetMapping("show/{id}")
    public Result show(@PathVariable("id") Long id) {
        //最终要返回用户信息和就诊人信息所以用mao集合
        Map<String, Object> result = new HashMap<>();
        result = userService.show(id);
        return Result.ok(result);
    }

    @PutMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable("userId") Long userId,
                           @PathVariable("authStatus") Integer authStatus) {
        userService.approval(userId, authStatus);
        return Result.ok();
    }

}
